import { checkNameForm } from "../../common/commonFormRuler_string";
import { dataSourceType, } from "@/type.d";
const noChinese = (_rule: dataSourceType, value: string, callback: () => {}, type = 'noChinese', msg = '不能输入中文', useValue: number = 0) => {
  if (_rule.required) {// 必填项验证非空并排除非必须项
    if (!useValue) { // 使用fullField校验
      if ((value === '' || value === null || value === undefined)) {
        return Promise.reject('密码不能为空！');
      } else {
        const reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
        return !reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${msg}`) : Promise.reject(`${_rule.msg}`);
      }
    } else {
      if (!value || value == undefined) {
        return Promise.reject(`${_rule.msg1}`);
      } else {
        const reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
        return !reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${msg}`) : Promise.reject(`${_rule.msg}`);
      }
    }
  } else {
    if (!useValue) {
      if ((value === '' || value === null || value === undefined)) {
        return Promise.resolve();
      } else {
        const reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
        return !reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${msg}`) : Promise.reject(`${_rule.msg}`);
      }
    } else {
      if (!value || value == undefined) {
        return Promise.resolve();
      } else {
        const reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
        return !reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${msg}`) : Promise.reject(`${_rule.msg}`);
      }
    }
  }
}
export default {
  component: {//展示型组件信息，每个组件的信息各不相同
    componentName: 'password', // 组件名称
    settings: {// 对应的设置项， 可能不同组件设置也不尽相同。
      value: '',
      placeholder: '请输入密码',
      param: 'password',
      rule: {
        required: true,
        validator: noChinese,
        trigger: ["blur", "change"],
        msg1: '密码不能为空！',
        msg2: '密码不能重复!',
        api: "fetchOssNameUnique",
        key: 'siteDomain',
        params: {}, //校验传参
      },
      label: "密码:",
      beforeText: '',
      afterText: '',
      helpMsg: '',
      api: "fetchOssNameUnique",
      width: 492,
      maxCount: 25,
      marginLeft: 32,
      marginTop: 0,
      showPassword: true,
      type: 'textInput',
      associated: '',
      associatedValue: '',
    },
  }
}